﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace System.Xml
{
    public class XmlNode : IEnumerable<XmlNode>
    {
        public List<XmlNode> ChildNodes { get; set; }
        public virtual string Name { get; set; }
        public string InnerText { get; set; }
        public string Value { get; set; }

        public XmlNode()
        {
            ChildNodes = new List<XmlNode>();
        }

        public XmlNode FirstChild
        {
            get
            {
                if (this.ChildNodes.Count > 0)
                {
                    return this.ChildNodes[0];
                }
                else
                {
                    return null;
                }
            }
        }

        public XmlNode SelectSingleNode(string xpath)
        {
            XmlNode retNode = null;

            foreach (XmlNode node in this.ChildNodes)
            {
                if (node.Name == xpath)
                {
                    retNode = node;
                    break;
                }
            }

            return retNode;
        }

        IEnumerator<XmlNode> IEnumerable<XmlNode>.GetEnumerator()
        {
            return this.ChildNodes.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.ChildNodes.GetEnumerator();
        }
    }
}
